/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* rotateRight(ListNode* head, int k) {
        if (!head)return head;
        if (!k)return head;
        if (!(head->next))return head;
        ListNode* p = head;
        int n = 1;
        while (p->next) {
            n++;
            p = p->next;
        }
        k = n - k % n;
        if (k == n)return head;
        cout << "k=" << k << endl;
        p->next = head;
        cout << "x==" << p->next->val << endl;
        while (k--) {
            p = p->next;
        }
        ListNode* res = p->next;
        p->next = nullptr;
        return res;
    }
};